using System;
using System.Collections.Generic;
using System.Text;
using AF_ORM.CORE;
using System.Data;
using Bussiness.Entity;
using System.Data.SqlClient;
namespace Bussiness.Manager
{
                

    public class PT_ActionHistoryManager:Bussiness.ManagerBase.PT_ActionHistoryManagerBase
    {
            public static PT_ActionHistoryManager CreateInstant()
            {
                return new PT_ActionHistoryManager();
            }
            // user action history
            public void SaveHistory(int UserId,string ActionName, string Description)
            {
                PT_ActionHistoryEntity obj = new PT_ActionHistoryEntity();
                obj.UserId = UserId;

                obj.ActionDate = DateTime.Now;
                obj.ActionName = ActionName;
                obj.Description = Description;

                PT_ActionHistoryManager.CreateInstant().Insert(obj);
            }
            public DataTable search(DateTime from, DateTime to,string SoPhieu)
            {
                string sql = @"SELECT ah.*, a.UserCode, a.UserName
                               FROM PT_ActionHistory ah INNER JOIN PT_Account a ON ah.UserId=a.UserId
                               WHERE datediff(second,ah.ActionDate,@from)<=0 AND datediff(second,ah.ActionDate,@to)>=0
                                     AND [Description] like '%" + SoPhieu + @"%'
                               ORDER BY ah.ActionDate";
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", from);
                param[1] = new SqlParameter("@to", to);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
            }
    }
}
                    
